package com.hqully.smartfumehood.controller;


import com.github.pagehelper.PageInfo;
import com.hqully.smartfumehood.common.utils.PermissionUtil;
import com.hqully.smartfumehood.common.utils.ResultVoUtil;
import com.hqully.smartfumehood.common.vo.QueryVo;
import com.hqully.smartfumehood.common.vo.ResultVo;
import com.hqully.smartfumehood.entity.DevRecord;
import com.hqully.smartfumehood.entity.dto.DevRecordDto;
import com.hqully.smartfumehood.service.DevRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *     设备记录controller
 * </p>
 * @author liulingyu
 * @date 2022-03-09 10:48
 * @version 1.0
 */
@RestController
@RequestMapping("/api/dev-record")
public class DevUsageRecordController extends BaseController{
    @Autowired
    private DevRecordService devRecordService;

    @PostMapping("/find-all-dev-record")
    public ResultVo findAllDevUsageRecord(@RequestHeader("token") String token,@RequestBody QueryVo queryVo){

        QueryVo realQueryVo = PermissionUtil.setQueryUnitId(token, queryVo);


        PageInfo<DevRecordDto> allDevUsageRecord = devRecordService.findAllRecord(realQueryVo);


        return ResultVoUtil.success(allDevUsageRecord);
    }

    @PostMapping("/find-record-by-dev-id")
    public ResultVo findRecordByDevId(@RequestBody QueryVo queryVo){
        PageInfo<DevRecord> allDevUsageRecord = devRecordService.findRecordByDid(queryVo);


        return ResultVoUtil.success(allDevUsageRecord);
    }

    @PostMapping("/add-dev-record")
    public ResultVo addDevUsageRecord(@RequestBody DevRecord devRecord){
        int status = devRecordService.addRecord(devRecord);


        return ResultVoUtil.success("添加设备记录成功");
    }

    @PostMapping("/delete-dev-record")
    public ResultVo deleteDevUsageRecord(@RequestBody DevRecord devRecord){
        devRecordService.deleteRecord(devRecord.getId());

        return ResultVoUtil.success("删除设备记录成功");
    }

    @PostMapping("/update-dev-record")
    public ResultVo updateDevUsageRecord(@RequestBody DevRecord devRecord){
        devRecordService.updateRecord(devRecord);

        return ResultVoUtil.success("更新设备记录成功");
    }

}
